<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>

<body>
  <script type="text/javascript">
    function print(v) {
      if (typeof v == "number") {
        var w = 30;
        if (n > 30) w = (n - 30) + 40;
        var s = '<span style="padding:4px 2px;display:inline-block;text-align:center;width:' + w + 'px;">' + v + '</span>';
        document.write(s);
      } else {
        document.write(v);
      }
    }
    function c(x, y) {
      if ((y == 1) || (y == x + 1)) return 1; // 头尾都是1  [0, 1] =>  [1. 1][1. 2] => [2. 1][2. 2][2. 3]
      return c(x - 1, y - 1) + c(x - 1, y); // 中间的计算规则取上面的肩膀值之和
    }
    // 开始
    var n = prompt("请输入行数：", 9);
    n = n - 1;
    var t1 = new Date(); // 开始时间记录
    print('<div style=text-align:center;">');
    for (var i = 0; i <= n; i++) {
      for (var j = 1; j <= i + 1; j++) { // 每一行的个数是 i + 1 个
        print(c(i, j));
      }
      print("<br />"); // 一行打完给个回车换行
    }
    print("</div>");

    var t2 = new Date(); // 计算结束时间记录
    print("<p style='text-align:center;'>耗时为（毫秒）：" + (t2 - t1) + "</p>");


  </script>
</body>

</html>